<template>
  <div class="kd_header">
    <div class="kd_header_title">
      <h1>叩丁狼电商运营平台</h1>
      <el-icon color="#fff" size="23" @click="menuShow = !menuShow"
        ><Menu
      /></el-icon>
    </div>
    <div class="kd_header_dropdown">
      <el-dropdown @command="handleClick">
        <span class="el-dropdown-link" style="color: #fff">
          {{ userState.username }}
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="index">首页</el-dropdown-item>
            <el-dropdown-item command="login">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, inject } from "vue";
import { useUserStore } from "@/store/user";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";
import { logout } from "@/common";
import {userLogoutApi} from '@/http/api'
const router = useRouter();
const menuShow = inject("menuShow");
const userState = useUserStore();
// console.log(menuShow);
const handleClick = (command: string) => {
  if (command == "index") {
    // 1、跳转首页
    router.push("/");
  } else if (command == "login") {
    logout(
      () => {
        userLogoutApi()
      },
      () => {
        ElMessage.success("退出成功");
      }
    );
  }
};
</script>

<style lang="scss" scoped>
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
.kd_header {
  display: flex;
  justify-content: space-between;
  .kd_header_title,
  .kd_header_dropdown {
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    h1 {
      color: #fff;
      font-weight: 400;
      padding-right: 20px;
    }
  }
}
</style>
